package org.execute.tool.excel处理.对象转为excel.查询语句的结果转为excel;

import lombok.Data;
import lombok.ToString;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;

@Data
@ToString
public class ResulTable {
    private ExecuteSql executeSql;
    private ArrayList<String> header=new ArrayList<>();
    private ArrayList<ArrayList> row=new ArrayList<>();
    private Date creationTime;

    public void storeResultSet(ResultSet rs) {
        try {
            ResultSetMetaData metaData = rs.getMetaData();
            int columnCount = metaData.getColumnCount();

            // 存储表头
            for (int i = 1; i <= columnCount; i++) {
                header.add(metaData.getColumnName(i));
            }

            // 存储数据行
            while (rs.next()) {
                ArrayList<String> rowData = new ArrayList<>();
                for (int i = 1; i <= columnCount; i++) {
                    rowData.add(rs.getString(i));
                }
                row.add(rowData);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
